import vue from '@vitejs/plugin-vue';
import autoprefixer from 'autoprefixer';
import { codeInspectorPlugin } from 'code-inspector-plugin';
import UnoCss from 'unocss/vite';
import AutoImport from 'unplugin-auto-import/vite';
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
import Components from 'unplugin-vue-components/vite';
import { fileURLToPath, URL } from 'url';
import { defineConfig } from 'vite';

/* 配置信息 */
export default defineConfig(() => {
  return {
    base: '/',
    plugins: [
      vue(),
      codeInspectorPlugin({
        bundler: 'vite',
      }),
      UnoCss({ configFile: './uno.config.ts' }),
      AutoImport({
        dts: 'src/auto-imports.d.ts',
        imports: ['vue', 'vue-router', 'pinia', 'vue-i18n'],
        eslintrc: {
          enabled: true,
          filepath: './.eslintrc-auto-import.json',
          globalsPropValue: true,
        },
      }),
      Components({
        dts: 'src/components.d.ts',
        deep: true,
        dirs: ['src/components'],
        extensions: ['vue', 'tsx'],
        resolvers: [
          AntDesignVueResolver({
            importStyle: false,
            resolveIcons: true,
          }),
        ],
      }),
    ],
    assetsInclude: ['**/*.xlsx', '**/*.xls'],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url)),
      },
    },

    css: {
      scss: {
        api: 'modern-compiler', // or 'modern'
      },
      postcss: {
        plugins: [autoprefixer],
      } as any,
    },
    optimizeDeps: {
      include: ['@ant-design/icons-vue', 'ant-design-vue', 'vue-use'],
    },
    server: {
      /* 是否自动打开，在linux上运行请关闭，否则会报错 */
      open: true,
      port: 5678,
    },
  };
});
